package com.example.bzh.gamecat.httputils.newestutils;

import android.util.Log;

import com.example.bzh.gamecat.bean.SocietyBean;
import com.example.bzh.gamecat.bean.newest.Newest;
import com.example.bzh.gamecat.httputils.RetrofitHelper;
import com.example.bzh.gamecat.ui.society.ISocietyService;

import java.util.HashMap;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class NewestHttpUtil {

    private static NewestHttpUtil instance;

    private NewestHttpUtil(){
    }

    public static synchronized NewestHttpUtil getInstance(){
        if (instance == null){
            instance = new NewestHttpUtil();
        }
        return instance;
    }

    public interface HttpCallBack<T>{
        public void onSucess(T t);

        public void onFail();
    }

    public void getNewest(HashMap<String,String> params, final HttpCallBack<Newest> newestHttpCallBack){
        Call<Newest> beanCall = RetrofitHelper
                .getInstance()
                .createRetrofitService(NewestService.class)
                .getNewestBean(params);
        beanCall.enqueue(new Callback<Newest>() {
            @Override
            public void onResponse(Call<Newest> call, Response<Newest> response) {
                Newest body = response.body();
                Log.i("path","body=="+response.toString());
                newestHttpCallBack.onSucess(body);
            }

            @Override
            public void onFailure(Call<Newest> call, Throwable t) {
                newestHttpCallBack.onFail();
            }
        });
    }

}
